import * as React from "react";
//hoistNonReactStatics是 提升非react静态方法,将老组件的非react静态属性提升到新的组件上
function hoistNonReactStatics<T extends React.ComponentType<any>,S extends React.ComponentType<any>
>(
    TargetComponent: T,
    SourceComponent: S
): T & S;
function hoistNonReactStatics<N extends React.ComponentType<any>, O extends React.ComponentType<any>>
(targetComponent:N , sourceComponent: O):N&O {
    let keys = Object.getOwnPropertyNames(sourceComponent); //['age1','propsTypes']
    for (let i = 0; i < keys.length; ++i) {
        const key = keys[i];
        const descriptor = Object.getOwnPropertyDescriptor(sourceComponent, key);
        Object.defineProperty(targetComponent, key, descriptor!);
    }
    return targetComponent as N&O;
}
interface Props{}
interface State{}
class Old extends React.Component<Props, State> {
    static age1: number = 10;
}

class New extends React.Component<Props, State> {
    static age2: number = 10;
}
let c = hoistNonReactStatics<typeof New, typeof  Old>(New, Old);
c.age1;
c.age2;